package com.szqhyxj.youxiangju.biz.merchantHome.plan.particulars;

import com.szqhyxj.youxiangju.biz.plan.PlanDetail;
import com.szqhyxj.youxiangju.biz.plan.PlanModel;
import com.szqhyxj.youxiangju.biz.plan.TasksItem;
import com.szqhyxj.youxiangju.sys.AbBasePresenter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/10/30.
 */

public class PlanParticularsPresenter extends AbBasePresenter implements PlanParticularsContract.Presenter {

    private PlanParticularsContract.View view;
    private List<List<Map<String, TasksItem>>> tasksList = new ArrayList<>();
    private List<PlanModel.PlanParticularsDayEntity> entityList = new ArrayList<>();
    private String money;

    public PlanParticularsPresenter(PlanParticularsContract.View view) {
        this.view = view;
    }

    @Override
    public void init(String planId) {

        addDisposables(
                PlanModel.getPlanDetail(planId)
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(Schedulers.io())
                        .subscribe(planDetailBaseResult -> {
                            PlanDetail planDetail = planDetailBaseResult.getData();
                            if(planDetail != null){
                                view.dismissLoading();
                                PlanModel.convertToDisplay(planDetail, tasksList, entityList);
                                view.showParticulars(planDetail);
                                view.showList(tasksList, entityList);
                               // view.showToast("个数"+money);
                            }
                        }, new Consumer<Throwable>(){
                            @Override
                            public void accept(Throwable throwable) throws Exception{
                                throwable.printStackTrace();
                                view.dismissLoading();
                                view.showToast(throwable.getMessage());
                            }
                        }));

    }

    @Override
    public void addDisposables(Disposable disposable) {
        super.addDisposables(disposable);
        view.showLoading();
    }

}
